package com.example.spareparts.controller;


import com.example.spareparts.entity.SparePart;
import com.example.spareparts.service.SparePartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/api/spareparts")
public class SparePartController {
    @Autowired
    private SparePartService sparePartService;
    @GetMapping ("/listall")
    public List<SparePart> findAllSparePart() {
        return sparePartService.findAllSparePart();
    }
    @PostMapping ("/insert")
    public SparePart insertSparePart(@RequestBody SparePart sparePart) {

        sparePartService.insertSparePart(sparePart);
        return sparePart;
    }
    @PutMapping ("/update/{sparepartid}")
    public void updateSparePart(@PathVariable Long sparepartid, @RequestBody SparePart sparePart) {
        sparePart.setSparepartid(sparepartid);
        sparePartService.updateSparePart(sparePart);
    }
    @DeleteMapping ("/delete/{sparepartid}")
    public void deleteSparePart(@PathVariable Long sparepartid) {
        sparePartService.deleteSparePart(sparepartid);
    }
    @GetMapping ("/findbyid/{sparepartid}")
    public SparePart findSparePartById(@PathVariable Long sparepartid) {
        return sparePartService.findSparePartById(sparepartid);
    }

    @GetMapping ("/findbysupplierid/{supplierid}")
    public List<SparePart> findSparePartBySupplierId(@PathVariable Long supplierid) {
        return sparePartService.findSparePartBySupplierId(supplierid);
    }
}